package org.holynite.fieldmanage.managed.support

import org.holynite.fieldmanage.ejbs.AuthorizationManagement
import org.holynite.fieldmanage.types.Privileges

import javax.annotation.PostConstruct
import javax.ejb.EJB
import javax.faces.bean.ApplicationScoped
import javax.faces.bean.ManagedBean

/**
 * Created by midnite on 15/1/31.
 */
@ManagedBean
@ApplicationScoped
class PrivilegesBean implements Serializable {
    List<Privileges> allPrivileges

    @EJB(beanName = "adminRoleControl")
    AuthorizationManagement roleService

    PrivilegesBean() {
        allPrivileges = []
    }

    @PostConstruct
    void initiate() {
        allPrivileges = roleService.allPrivileges
    }

    List<Privileges> selectPrivileges(List<String> selects) {
        allPrivileges.findAll { selects.contains(it.name()) }
    }
}
